package com.xs.demo.inteceptor;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;


import com.xs.demo.util.Constants;

public class PermissionsInteceptor implements HandlerInterceptor{

	@Override
	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		System.out.println("最后执行");
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {
		System.out.println("第二步执行");
	}
	public boolean isTimeOut(long old) {
		long now = new Date().getTime();
		long maxTime = Long.parseLong(Constants.SESSIONOUTTIME);
		if(now - old > maxTime*1000){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * 控制页面的访问
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object handler) throws Exception {
//		System.out.println("第一步");
//		String path = request.getServletPath();
//		if(path.startsWith("/user/")){
//			Userinfo userinfo = (Userinfo) request.getSession().getAttribute(Constants.LOGIN_INFO);
//			if(null == userinfo && !path.startsWith("/user/gotoAdd/")){
//				response.sendRedirect(request.getContextPath()+"/system/login.jsp");
//				return true;
//			}else{
//				return false;
//			}
//		}
//		System.out.println(handler.getClass().getName());
		return true;
	}

}
